<?php

use Drupal\shusy_team_achievement\Entity\ShusyTeamAchievement;

/**
 * Implements hook_rules_action_info().
 */
function shusy_team_achievement_rules_action_info() {
  return [
    'shusy_team_achievement_rules_action_achievement' => [
      'label' => t('记录业绩'),
      'parameter' => [
        'account' => [
          'label' => t('业绩人'),
          'type' => 'user',
          'description' => t('谁做的业绩'),
        ],
        'achievement' => [
          'label' => t('业绩额'),
          'type' => 'integer',
          'description' => t('业绩额,单位分'),
        ],
      ],
      'group' => t('shusy_team_achievement'),
    ],
    'shusy_team_achievement_rules_action_calculate' => [
      'label' => t('基于业绩计算收益'),
      'parameter' => [
        'achievement' => [
          'type' => 'shusy_team_achievement',
          'label' => t('业绩'),
        ],
      ],
      'group' => t('shusy_team_achievement'),
    ],
  ];
}

function shusy_team_achievement_rules_action_achievement($account, int $achievement) {
  $e = new ShusyTeamAchievement();
  $e->uid = $account->uid;
  $e->achievement = $achievement;
  $e->save();
}

function shusy_team_achievement_rules_action_calculate(ShusyTeamAchievement $achievement) {
  shusy_team_achievement($achievement);
}
